		TITLE	INSTCLASS - Copyright (C) 1994 SLR Systems

		INCLUDE	MACROS
		INCLUDE	SEGMENTS
		INCLUDE	CLASSES

		PUBLIC	INSTALL_CLASS,INSTALL_CLASS_SYMBOL,SEARCH_CLASS_SYMBOL


		.DATA

		EXTERNDEF	SYMBOL_TEXT:BYTE

		EXTERNDEF	CLASS_HASH_TABLE_PTR:DWORD,SYMBOL_LENGTH:DWORD,SYMBOL_HASH:DWORD,CLASS_NAME_LINDEX:DWORD
		EXTERNDEF	CLASS_HASH:DWORD

		EXTERNDEF	CLASS_GARRAY:STD_PTR_S,LNAME_LARRAY:LARRAY_STRUCT,SYMBOL_TPTR:TPTR_STRUCT

		EXTERNDEF	CASE_STRING_COMPARE:DWORD


		.CODE	PASS1_TEXT


INSTALL_CLASS	PROC
		;
		;CLASS_NAME_VPTR IS CLASS NAME, PUT IT IN SYMBOL_HASH
		;
		PUSHM	EDI,ESI

		MOV	EAX,CLASS_NAME_LINDEX
		PUSH	EBX

		CONVERT_LINDEX_EAX_EAX	LNAME_LARRAY,ESI
		ASSUME	EAX:PTR TPTR_STRUCT

		MOV	EDI,OFF SYMBOL_TPTR
		ASSUME	EDI:PTR TPTR_STRUCT
		MOV	EBX,[EAX]._TP_FLAGS

		MOV	EDX,[EAX]._TP_HASH
		LEA	ESI,[EAX]._TP_TEXT

		MOV	ECX,[EAX]._TP_LENGTH
		ADD	EDX,EBX

		MOV	[EDI]._TP_LENGTH,ECX
		POP	EBX

		SHR	ECX,2
		MOV	[EDI]._TP_HASH,EDX

		INC	ECX
		LEA	EDI,[EDI]._TP_TEXT

		OPTI_MOVSD

		POPM	ESI,EDI

INSTALL_CLASS_SYMBOL	LABEL	PROC
		;
		;SYMBOL_TEXT CLASS NAME, DX IS HASH, RETURNS AX=INDEX, DS:BX PHYS
		;
		CALL	SEARCH_CLASS_SYMBOL

		JC	DO_CLASS_INSTALL

		CMP	ESP,-1

		RET

DO_CLASS_INSTALL:
		;
		;
		;
		PUSHM	EDI,ESI,EBX
		MOV	EAX,SYMBOL_LENGTH
		PUSH	EDX			;SAVE HASH
		ADD	EAX,SIZE CLASS_STRUCT-3
		CLASS_POOL_ALLOC		;ES:DI IS PHYS, AX LOG
		MOV	ESI,ECX
		ASSUME	ESI:PTR CLASS_STRUCT
		MOV	EBX,EAX
		ASSUME	EBX:PTR CLASS_STRUCT
		INSTALL_POINTER_GINDEX	CLASS_GARRAY
		MOV	[ESI]._C_NEXT_HASH_GINDEX,EAX
		MOV	EDX,EAX			;SAVE INDEX
		XOR	EAX,EAX
		MOV	ECX,CLASS_STRUCT._C_TEXT/4
		MOV	EDI,EBX
		MOV	ESI,OFF SYMBOL_TEXT
		ASSUME	ESI:NOTHING
		REP	STOSD
		MOV	ECX,[ESI-4]
		POP	EAX			;HASH
		PUSHM	ESI,ECX
		SHR	ECX,2
		MOV	[EBX]._C_HASH,EAX
		INC	ECX
		REP	MOVSD
		;
		;SEE IF THIS IS A CODE CLASS
		;
		POPM	ECX,ESI
		SUB	ECX,4
		JC	L8$			;TOO SHORT FOR CODE OR DEBUG
		MOV	EAX,[ESI+ECX]		;LOOK AT LAST FOUR CHARACTERS
		LEA	ESI,[ESI+ECX+2]
		CMP	EAX,'EDOC'
		JZ	L4$
		TO_UPPER
		CMP	AL,'C'
		JNZ	L8$
		MOV	AL,AH
		TO_UPPER
		CMP	AL,'O'
		JNZ	L8$
		MOV	AL,[ESI]
		INC	ESI
		TO_UPPER
		CMP	AL,'D'
		JNZ	L8$
		MOV	AL,[ESI]
		TO_UPPER
		CMP	AL,'E'
		JNZ	L8$
L4$:
		OR	[EBX]._C_TYPE_FLAG,MASK SEG_CLASS_IS_CODE
if	any_overlays
		BITT	CMDLINE_FREEFORMAT
		JNZ	L8$
		OR	[EBX]._C_PLTYPE,MASK SEG_OVERLAYABLE
endif
L8$:
		MOV	ECX,EBX
		POPM	EBX,ESI,EDI
		MOV	EAX,EDX			;INDEX #
		OR	EDX,EDX			;INSTALL SUCCESS
		RET

INSTALL_CLASS	ENDP


SEARCH_CLASS_SYMBOL	PROC
		;
		;EDX IS HASH
		;
		PUSHM	EDI
		MOV	EAX,EDX

		XOR	EDX,EDX
		MOV	EDI,EAX

		MOV	ECX,CLASS_HASH_TABLE_PTR

		HASHDIV	CLASS_HASH

		PUSHM	ESI,EBX

		MOV	EAX,DPTR [ECX+EDX*4]
		LEA	EBX,[ECX+EDX*4 - CLASS_STRUCT._C_NEXT_HASH_GINDEX]
CLASS_NEXT:
		TEST	EAX,EAX
		JZ	DO_SEARCH_FAIL

		MOV	EDX,EAX
		CONVERT	EAX,EAX,CLASS_GARRAY
		ASSUME	EAX:PTR CLASS_STRUCT
		MOV	EBX,EAX

		MOV	ECX,[EAX]._C_HASH
		MOV	EAX,[EAX]._C_NEXT_HASH_GINDEX

		CMP	ECX,EDI
		JNZ	CLASS_NEXT
		;
		;HASH MATCHED, TRY ACTUAL TEXT COMPARE...
		;
		PUSH	EDI
		MOV	EDI,OFF SYMBOL_TEXT

		MOV	ECX,SYMBOL_LENGTH
		LEA	ESI,[EBX]._C_TEXT

		CALL	CASE_STRING_COMPARE

		POP	EDI
		JNZ	CLASS_NEXT

		MOV	ECX,EBX
		POPM	EBX,ESI,EDI

		MOV	EAX,EDX
		OR	EDX,EDX				;SEARCH SUCCEED

		RET

DO_SEARCH_FAIL:
		CMP	ESP,-1
		MOV	ECX,EBX

		POPM	EBX,ESI

		MOV	EDX,EDI
		POP	EDI

		RET

SEARCH_CLASS_SYMBOL	ENDP


		END

